// 生成动态路由
const generateRouters = data => {
  return new Promise((resolve, reject) => {
    if (data.auth && data.auth.length) {
      let newRouters = [];
      let children = [];
      data.auth.map(item => {
        let obj = {
          path: item.path,
          name: item.routerName,
          component: () => import(`@/views/${item.component}`),
          hidden: item.hidden ? true : false,
          meta: {
            title: item.name,
            icon: item.icon,
            activeMenuTitle: item.pageHeaderName,
            activeMenu: item.activeMenuPath
          }
        };
        children.push(obj);
      });
      let layoutPath = {
        path: '/',
        component: () => import('@/views/layout/index.vue'),
        redirect: children[0].path,
        hidden: true,
        children
      };
      newRouters.push(layoutPath);
      resolve(newRouters);
    } else {
      resolve([]);
    }
  });
};

export default generateRouters;
